package cn.iocoder.yudao.module.ai.graph.dispatcher;

import com.alibaba.cloud.ai.graph.OverAllState;
import com.alibaba.cloud.ai.graph.StateGraph;
import com.alibaba.cloud.ai.graph.action.EdgeAction;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 客服工作流分发器 - 根据人工审核结果决定下一步流程
 * 
 * @author yudao
 * @since 2025/10/17
 */
public class CustomerServiceDispatcher implements EdgeAction {

    private static final Logger logger = LoggerFactory.getLogger(CustomerServiceDispatcher.class);

    @Override
    public String apply(OverAllState state) throws Exception {
        // 获取人工决策
        String decision = (String) state.value("human_decision", "send_reply");
        
        logger.info("🔀 路由决策：{}", decision);
        
        // 验证决策是否有效
        switch (decision) {
            case "send_reply":
                logger.info("→ 发送回复给客户");
                return "send_reply";
                
            case "transfer_to_human":
                logger.info("→ 转接人工客服");
                return "transfer_to_human";
                
            case "escalate":
                logger.info("→ 升级到高级支持");
                return "escalate";
                
            case "end":
            case StateGraph.END:
                logger.info("→ 结束流程");
                return StateGraph.END;
                
            default:
                logger.warn("未知的决策：{}，默认发送回复", decision);
                return "send_reply";
        }
    }
}

